package com.chinadci.smartcommunitysystembackstage.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.chinadci.smartcommunitysystembackstage.entity.ScsActivity;
import com.baomidou.mybatisplus.extension.service.IService;
import com.chinadci.smartcommunitysystembackstage.entity.ScsNotice;
import com.chinadci.smartcommunitysystembackstage.mapper.ScsActivityMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务类
 * </p>
 *
 * @author Code Duck
 * @since 2021-04-13
 */
@Service
public class ScsActivityService{
    @Autowired
    private ScsActivityMapper mapper;

    private Logger log= LoggerFactory.getLogger(this.getClass());

    //查询全部社区活动
    public List<ScsActivity> Find(String type){
        log.info("=====查询全部社区活动");
        List<ScsActivity> list=null;
        if (type!="" & type!=null){
            list=mapper.Finds(type);
        }else{
            list=mapper.Find();
        }
        for (int i = 0; i <list.size() ; i++) {
            list.get(i).setName(list.get(i).getAdmin().get(0).getAName());
        }
        return list;
    }


    //新增活动
    public int Insert(ScsActivity scs){
        log.info("=====添加活动");
        return mapper.insert(scs);
    }

    //删除活动
    public int Del(int id){
        log.info("=====删除活动");
        QueryWrapper<ScsActivity> qw=new QueryWrapper<>();
        qw.eq("a_id",id);
        return mapper.delete(qw);
    }

    //修改活动
    public int Update(ScsActivity scs){
        log.info("=====修改活动");
        return mapper.updateById(scs);
    }

    //查找修改活动
    public List<ScsActivity> Finds(int id){
        log.info("=====查找修改活动");
        List<ScsActivity> list= mapper.Findinsert(id);
        return list;
    }

}
